/**
 * 
 */
package com.java.test.system.mapper;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.java.test.system.dto.LogInfo;
import com.java.test.util.PageInfo;

/**
 * @author Administrator
 *
 */
@Component
public class LogInfoMapper {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public int selectoperlogCount(LogInfo info) {

		String sql = "select count(*) from system_log where 1=1";

		if (info.getCreateTime() != null) {
			sql += " and TO_DAYS(create_time)= TO_DAYS('" + info.getCreateTime() + "')";
		}

		if (info.getAccount() != null && !"".equals(info.getAccount())) {
			sql += " and account like '%" + info.getAccount() + "%'";
		}

		int i = jdbcTemplate.queryForObject(sql, Integer.class);

		return i;
	}

	public List<LogInfo> selectoperlogList(LogInfo info, PageInfo<LogInfo> page) {

		String sql = "select * from system_log where 1=1";

		if (info.getCreateTime() != null) {
			sql += " and TO_DAYS(create_time)= TO_DAYS('" + info.getCreateTime() + "')";
		}

		if (info.getAccount() != null && !"".equals(info.getAccount())) {
			sql += " and account like '%" + info.getAccount() + "%'";
		}

		int start = (page.getCurrentPage() - 1) * page.getPageCount();
		int limit = page.getPageCount();

		sql += " order by create_time desc limit ?,?";

		List<LogInfo> list = jdbcTemplate.query(sql, new LogInfo(), start, limit);

		return list;
	}

	public int insertlogInfo(LogInfo info) {
		String sql = "insert into system_log(account,content,create_time,ip_address)values(?,?,?,?)";
		int i = jdbcTemplate.update(sql, info.getAccount(), info.getContent(), info.getCreateTime(),
				info.getIpAddress());
		return i;
	}

}
